<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加分类</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link type="text/css" rel="stylesheet" href="statics/css/style.css" />
	
	
	<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="/EasyBuy/statics/js/menu.js"></script>
	
	<script type="text/javascript" src="/EasyBuy/statics/js/select.js"></script>
  </head>
  <script type="text/javascript"
		src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#bto").click(function(){
				if($("#productname").val() == ""){
					alert("请输入分类名称");
				}else if($("#cosmetics").val() == "0"){
					alert("请选择分类级别");
				}else if($("#face").val()=="0" && $("#cosmetics").val()!="1"){
					alert("请选择父级分类");
				}else{
					var productname=$("#productname").val();
					var cosmetics=$("#cosmetics").val();
					var face=$("#face").val();
					alert(face);
					$.get("CommodityInformationServlet","opr=productCategoryAdd&productname="+productname+"&cosmetics="+cosmetics+"&face="+face,callBackAdd);
					function callBackAdd(data){					
						if(data==1){
							alert("添加成功！");
							location.href="backend/productCategory/ProductCategoryList.jsp";
						}else{
							alert("添加失败！");
							location.href="backend/productCategory/ProductCategoryList.jsp";
						}
					}
				}
			});
			$("#cosmetics").change(function(){
				if($("#cosmetics").val()=="1"){
					$("#face").html("");
					$("#face").append("<option selected='selected' value='0'>无</option>");
				}else if($("#cosmetics").val()=="2"){
					$.getJSON("CommodityInformationServlet","opr=categoryOneName",callBackOne);
					function callBackOne(dataOne){
						$("#face").html("");
						$("#face").append("<option selected='selected' value='0'>请选择</option>");
						for(var i=0;i<dataOne.length;i++){
							$("#face").append("<option value='"+dataOne[i].id+"'>"+dataOne[i].name+"</option>");
						}
					}
				}else if($("#cosmetics").val()=="3"){
					$.getJSON("CommodityInformationServlet","opr=categoryTwoName",callBackTwo);
					function callBackTwo(dataTwo){
						$("#face").html("");
						$("#face").append("<option selected='selected' value='0'>请选择</option>");
						for(var i=0;i<dataTwo.length;i++){
							$("#face").append("<option value='"+dataTwo[i].id+"'>"+dataTwo[i].name+"</option>");
						}
					}
				}
			});
		});
	</script>
  <body>
	<%@ include file="../../common/header.jsp" %>
    <%@ include file="../../common/backendHeader.jsp" %>
   	
   	<c:choose>
		<c:when test="${empty applicationScope.type }">
			<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=AddInfo&href1=productCategory").forward(request, response); %>
		</c:when>
		<c:otherwise>
			<c:if test="${applicationScope.type==1 }">
  				<%@ include file="../../common/sideMamber.jsp" %> 
			</c:if>
			<c:if test="${applicationScope.type==0 }">
				<%@ include file="../../common/sideUser.jsp" %> 
			</c:if>
		</c:otherwise>
	 </c:choose>
   
			<div class="m_right">
				<p></p>
				<div class="mem_tit">添加分类</div>
				<form id="form">
				<table border="0" class="order_tab"
					style="width:930px; text-align:center; margin-bottom:30px;"
					cellspacing="0" cellpadding="0">
					 <tr>
						<td width="25%"  height="50px" align="right">分类名称</td>
						<td align="left"><input type="text" name="productname" id="productname"style="width:200px">(必填)</td>
					</tr>
					<tr>
						<td width="25%" height="50px" align="right">分类级别</td>
						<td align="left">
							<select name="cosmetics" id="cosmetics" style="width:200px">
								<option selected="selected" value="0">请选择</option>
								<option value="1">一级分类</option>
								<option value="2">二级分类</option>
								<option value="3">三级分类</option>
							</select>
						</td>
					</tr>
   		 
			   		 <tr>
						<td width="25%" height="50px" align="right">父级分类</td>
						<td align="left">
							<select name="face" id="face"style="width:200px">
								<option selected="selected" value="0">请选择</option>
								<c:forEach items="${productCategoryTypes }" var="types">
									<option value="${types.id }">${types.name }</option>
								</c:forEach>
							</select>
						</td>
					</tr>

					<tr>
						<td width="25%"  height="50px"></td>
						<td align="left">
							<input name ="tj" type="button" id="bto" value="提交 " onClick="search();" class="tj" style="width:200px"/> 
						</td>
					</tr>
				</table>
				</form>	
			</div>
		</div>
    <%@ include file="../../common/footer.jsp" %>

  </body>
</html>
